import 'package:basic_common/app_theme.dart';
import 'package:basic_common/bottom_sheet_tool.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/button_widget.dart';
import 'package:basic_widgets/input_widget.dart';

import '../realname_controller.dart';

class IdentityView extends GetView<RealNameController> {
  const IdentityView({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: ScreenHelper.screenHeight - ScreenHelper.height(220),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Obx(() => buildInputInfoItem(
              attrName: "医护类型",
              arrowChild: selectItem(text: controller.selectCare.value),
              onTap: () {
                BottomSheetTool.singlePickerView(
                    dataList: controller.careTypeList,
                    selectData: controller.selectCare.value,
                    onConfirm: (res, int) {
                      controller.selectCare.value = res;
                      controller.selectCarelId.value =
                          controller.careIdList[int];
                      FocusManager.instance.primaryFocus?.unfocus();
                    });
              })),
          Obx(() => buildInputInfoItem(
              attrName: "所在医院",
              arrowChild: selectItem(text: controller.selectHospital.value),
              onTap: () {
                if (controller.hospitalList.isEmpty) {
                  return ToastUtils.toast("列表为空");
                }
                BottomSheetTool.singlePickerView(
                    dataList: controller.hospitalList.value,
                    selectData: controller.selectHospital.value,
                    onConfirm: (res, int) {
                      controller.selectHospital.value = res;
                      controller.selectHospitalId.value =
                          controller.allHospitalList[int].hospNo.toString();

                      controller.getDepartmentList();
                    });
              })),
          Obx(
            () => buildInputInfoItem(
                attrName: "科室",
                arrowChild: selectItem(
                    text: controller.selectKeshiNameList.isEmpty
                        ? '请选择您的科室'
                        : controller.selectKeshiNameList[1]),
                onTap: () {
                  controller.selectKeshiIdList.clear();
                  controller.selectKeshiNameList.clear();
                  BottomSheetTool.showPickerDialog(Get.context!,
                      allkeshiMap: controller.allKeshiDataList,
                      keshiMap: controller.allKeshiList,
                      labelKey: 'hospitalNo',
                      title: '选科室',
                      selectINameList: controller.selectKeshiNameList,
                      selectIdList: controller.selectKeshiIdList,
                      onConfirm: (Picker picker, List value) {
                    List<dynamic> select = picker.getSelectedValues();
                    for (int i = 0; i < select.length; i++) {
                      Set newStr = controller.allKeshiDataList
                          .where((ele) => ele['departmentName'] == select[i])
                          .toSet();
                      List idList = newStr.toList();
                      List new1 = idList
                          .map((element) => element['departmentNo'])
                          .toList();
                      controller.selectKeshiIdList.addAll(new1);
                    }
                    controller.selectKeshiNameList.value = select;
                  });
                  controller.getDutyList(type: "doctor_title");
                }),
          ),
          Obx(() => buildInputInfoItem(
              attrName: "职称",
              arrowChild: selectItem(text: controller.selectTitle.value),
              onTap: () {
                if (controller.drTitleList.isEmpty) {
                  return ToastUtils.toast("列表为空");
                }
                BottomSheetTool.singlePickerView(
                    dataList: controller.drTitleList.value,
                    selectData: controller.selectTitle.value,
                    onConfirm: (res, int) {
                      controller.selectTitle.value = res;
                      controller.selectTitleId.value =
                          controller.allTitleList[int].dictValue.toString();
                    });
                controller.getDutyList(type: "doctor_duty");
              })),
          Obx(() => buildInputInfoItem(
              attrName: "职务",
              arrowChild: selectItem(text: controller.selectDuty.value),
              onTap: () {
                if (controller.dutyList.isEmpty) {
                  return ToastUtils.toast("列表为空");
                }
                BottomSheetTool.singlePickerView(
                    dataList: controller.dutyList.value,
                    selectData: controller.selectDuty.value,
                    onConfirm: (res, int) {
                      controller.selectDuty.value = res;
                      controller.selectDutyId.value =
                          controller.allDutyList[int].dictValue.toString();
                    });
              })),
          buildInputInfoItem(
              attrName: "昵称",
              arrowChild: inputBoxNoBorder(
                  hint: '请填写您的昵称',
                  inputController: controller.nickNameController)),
          Spacer(),
          _bottomWidget()
        ],
      ),
    );
  }

  /// 底部选择
  void bottomSelectWidget() {
    Pickers.showSinglePicker(Get.context!,
        data: controller.hospitalList,
        selectData: controller.selectHospital.value,
        onConfirm: (p, position) {
          controller.selectHospital.value = p;
        },
        onChanged: (data, position) => printInfo(info: "数据发生改变${data}"),
        pickerStyle: PickerStyle(
            commitButton: Padding(
          padding: EdgeInsets.only(right: ScreenHelper.width(10)),
          child: Text(
            "确定",
            style: TextStyle(color: AppTheme.dartTextColor),
          ),
        )));
  }

  Widget _bottomWidget() {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: ScreenHelper.width(30)),
      alignment: Alignment.centerLeft,
      margin: EdgeInsets.only(bottom: ScreenHelper.height(30)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(
            "请完成医生信息相关认证，否则将无法使用医生端相关功能",
            style: TextStyle(
                color: AppTheme.dartWeakTextColor,
                fontSize: ScreenHelper.sp(12)),
          ),
          SizedBox(
            height: ScreenHelper.height(15),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            mainAxisSize: MainAxisSize.min,
            children: [
              roundBtn(
                  text: '上一步',
                  borderColor: AppTheme.hintTextColor,
                  isEnable: true,
                  bgColor: Colors.white,
                  width: ScreenHelper.width(115),
                  onTap: () {
                    controller.preStep();
                  }),
              SizedBox(
                width: ScreenHelper.width(10),
              ),
              Obx(
                () => roundBtn(
                    text: '提交医生身份信息',
                    isEnable: true,
                    borderColor: controller.checkBtnStatus()
                        ? AppTheme.primyColor
                        : AppTheme.primyColor,
                    bgColor: controller.checkBtnStatus()
                        ? AppTheme.primyColor
                        : AppTheme.primyColor,
                    textColor: Colors.white,
                    width: ScreenHelper.width(170),
                    onTap: () {
                      controller.addDrInfo();
                      // controller.currentStep.value = 2;
                    }),
              )
            ],
          )
        ],
      ),
    );
  }
}
